# Contributor: @ifurther <55025025+ifurther@users.noreply.github.com>

_realname=pipenv
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=2022.12.19
pkgrel=1
pkgdesc="Python Development Workflow for Humans."
url="https://pipenv.pypa.io"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('spdx:MIT')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-certifi
	${MINGW_PACKAGE_PREFIX}-python-setuptools
	${MINGW_PACKAGE_PREFIX}-python-pip
    ${MINGW_PACKAGE_PREFIX}-python-virtualenv
	${MINGW_PACKAGE_PREFIX}-python-virtualenv-clone
)
makedepends=(${MINGW_PACKAGE_PREFIX}-python-setuptools)
source=(https://github.com/pypa/${_realname}/archive/refs/tags/v${pkgver}.tar.gz)
sha256sums=('52c9d07da58e178e0d33bb9e10272a4e0837404dd7248a704a569c3f6dcd7d8a')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"

  _PIPENV_COMPLETE=bash_source ${pkgdir}${MINGW_PREFIX}/bin/pipenv | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/pipenv"
  _PIPENV_COMPLETE=zsh_source  ${pkgdir}${MINGW_PREFIX}/bin/pipenv | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_pipenv"
  /usr/bin/env _PIPENV_COMPLETE=fish_source ${pkgdir}${MINGW_PREFIX}/bin/pipenv | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/pipenv.fish"
  
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py*; do
    sed -e '1 { s|^#!.*$|#!/usr/bin/env pythonw.exe|g }' -i ${_f}
  done
}
